#!/usr/bin/env node

//自己写客户端发出post请求
const http=require('http'),
      url=require('url'),
      log=console.log,
      msg=process.argv[2] || 'hello';

const addr='http://localhost:3000';
const opt=url.parse(addr);
opt.method='post';//delete没有请求体
//opt.heads={};//请求头的封装
//options=url.parse(global.encodeURI(addr));

const req=http.request(opt,(res)=>{
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
  log(res.headers);
  log('');

  res.pipe(process.stdout);
});

req.end(msg+'\n');

